package com.wuliupai.delivery.wuliupaidelivery.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.wuliupai.delivery.wuliupaidelivery.R;
import com.wuliupai.delivery.wuliupaidelivery.activity.PlaceOrderActivityV2;
import com.wuliupai.delivery.wuliupaidelivery.bean.LocationBean;
import com.wuliupai.delivery.wuliupaidelivery.bean.MyInfoBean;
import com.wuliupai.delivery.wuliupaidelivery.bean.OrderBean;

import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootContext;

/**
 * 类：
 * 作者：康慧丽
 * 时间：2016/6/15 15:45
 * 邮箱：khl8912@126.com
 */

@EBean(scope = EBean.Scope.Singleton)
public class SharePreferenceUtil {

    @RootContext
    Context mContext;

    /**
     * 保存用户是否保存支付密码
     *
     * @param context
     * @param payPasswordStauts
     */
    public static void setWhetherPayPassword(Context context, String payPasswordStauts) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(
                "paigeName", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("payPasswordStauts", payPasswordStauts);
        editor.commit();
    }

    /**
     * 获取是否设置过支付密码 0没有密码 1 有密码
     */
    public int getWhetherPayPassword() {
        SharedPreferences sharedPreferences = mContext.getSharedPreferences("paigeName", Context.MODE_PRIVATE);
        return Integer.parseInt(sharedPreferences.getString("payPasswordStauts", "0"));
    }

    /**
     * 设置是否绑定银行卡
     */
    public void setWhetherBank(int whetherBank) {
        SharedPreferences sharedPreferences = mContext.getSharedPreferences("paigeName", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("bankStauts", whetherBank + ""); // 是否设置绑定银行卡
        editor.commit();
    }

    /**
     * 获取是否绑定过银行卡 0没有银行卡 1 有银行卡
     */
    public int getWhetherBank() {
        SharedPreferences sharedPreferences = mContext.getSharedPreferences("paigeName", Context.MODE_PRIVATE);
        return Integer.parseInt(sharedPreferences.getString("bankStauts", "0"));
    }

    /**
     * 存储下单数据
     *
     * @param context
     * @param consignorName        发货人姓名
     * @param consignorMobile      发货人手机号
     * @param consigneeName        收货人姓名
     * @param consigneeMobile      收货人手机号
     * @param sProvinceCode        寄件地省
     * @param sCityCode            寄件地市
     * @param sAreaCode            寄件地县
     * @param sendDetailAddress    寄件地详细地址
     * @param eProvinceCode        收件地省
     * @param eCityCode            收件地市
     * @param eAreaCode            收件地县
     * @param receiveDetailAddress 收件地详细地址
     * @param goodsName            货物名称
     * @param goodsWeight          货物重量
     * @param goodsVolume          货物体积
     * @param dealPrice            运费
     * @param remarks              备注
     * @param payWay               支付方式
     * @param sProvinceCityArea    发货省市县
     * @param rProvinceCityArea    收货省市县
     */
    public static void saveOrderPlace(Context context, String consignorName, String consignorMobile, String consigneeName, String consigneeMobile, String sProvinceCode,
                                      String sCityCode, String sAreaCode, String sendDetailAddress, String eProvinceCode, String eCityCode, String eAreaCode, String receiveDetailAddress,
                                      String goodsName, String goodsWeight, String goodsVolume, String dealPrice, String remarks,
                                      String payWay, String sProvinceCityArea,
                                      String rProvinceCityArea, String calculateType, String goodsCount) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(
                "paigeOrderPlace", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("consignorName", consignorName);
        editor.putString("consignorMobile", consignorMobile);
        editor.putString("consigneeName", consigneeName);
        editor.putString("consigneeMobile", consigneeMobile);
        editor.putString("sProvinceCode", sProvinceCode);
        editor.putString("sCityCode", sCityCode);
        editor.putString("sAreaCode", sAreaCode);
        editor.putString("sendDetailAddress", sendDetailAddress);
        editor.putString("eProvinceCode", eProvinceCode);
        editor.putString("eCityCode", eCityCode);
        editor.putString("eAreaCode", eAreaCode);
        editor.putString("receiveDetailAddress", receiveDetailAddress);
        editor.putString("goodsName", goodsName);
        editor.putString("goodsWeight", goodsWeight);
        editor.putString("goodsVolume", goodsVolume);
        editor.putString("dealPrice", dealPrice);
        editor.putString("remarks", remarks);
        editor.putString("payWay", payWay);
        editor.putString("sProvinceCityArea", sProvinceCityArea);
        editor.putString("rProvinceCityArea", rProvinceCityArea);
        editor.putString("calculateType", calculateType);
        editor.putString("goodsCount", goodsCount);
        editor.commit();
    }

//    /**
//     * 获取下单数据
//     *
//     * @return
//     */
//    public static OrderBean getOrderPlace(Context context) {
//        OrderBean orderBean = new OrderBean();
//        SharedPreferences sharedPreferences = context.getSharedPreferences("paigeOrderPlace", Context.MODE_APPEND);
//        String consignorName = sharedPreferences.getString("consignorName", "");
//        String consignorMobile = sharedPreferences.getString("consignorMobile", "");
//        String consigneeName = sharedPreferences.getString("consigneeName", "");
//        String consigneeMobile = sharedPreferences.getString("consigneeMobile", "");
//        String sProvinceCode = sharedPreferences.getString("sProvinceCode", "");
//        String sCityCode = sharedPreferences.getString("sCityCode", "");
//        String sAreaCode = sharedPreferences.getString("sAreaCode", "");
//        String sendDetailAddress = sharedPreferences.getString("sendDetailAddress", "");
//        String eProvinceCode = sharedPreferences.getString("eProvinceCode", "");
//        String eCityCode = sharedPreferences.getString("eCityCode", "");
//        String eAreaCode = sharedPreferences.getString("eAreaCode", "");
//        String receiveDetailAddress = sharedPreferences.getString("receiveDetailAddress", "");
//        String goodsName = sharedPreferences.getString("goodsName", "");
//        String goodsWeight = sharedPreferences.getString("goodsWeight", "");
//        String goodsVolume = sharedPreferences.getString("goodsVolume", "");
//        String dealPrice = sharedPreferences.getString("dealPrice", "");
//        String remarks = sharedPreferences.getString("remarks", "");
//        String payWay = sharedPreferences.getString("payWay", "");
//        String sProvinceCityArea = sharedPreferences.getString("sProvinceCityArea", "");
//        String rProvinceCityArea = sharedPreferences.getString("rProvinceCityArea", "");
//        String calculateType = sharedPreferences.getString("calculateType","");
//        String goodsCount = sharedPreferences.getString("goodsCount","");
//        orderBean.setConsignorName(consignorName);
//        orderBean.setConsignorMobile(consignorMobile);
//        orderBean.setConsigneeName(consigneeName);
//        orderBean.setConsigneeMobile(consigneeMobile);
//        orderBean.setStartProvince(sProvinceCode);
//        orderBean.setStartCity(sCityCode);
//        orderBean.setStartArea(sAreaCode);
//        orderBean.setStartAddress(sendDetailAddress);
//        orderBean.setEndProvince(eProvinceCode);
//        orderBean.setEndCity(eCityCode);
//        orderBean.setEndArea(eAreaCode);
//        orderBean.setEndAddress(receiveDetailAddress);
//        orderBean.setGoodsVolume(goodsVolume);
//        orderBean.setGoodsName(goodsName);
//        orderBean.setGoodsWeight(goodsWeight);
//        orderBean.setDealPrice(dealPrice);
//        orderBean.setRemarks(remarks);
//        orderBean.setPayType(payWay);
//        orderBean.setsProvinceCityArea(sProvinceCityArea);
//        orderBean.setrProvinceCityArea(rProvinceCityArea);
//        orderBean.setCalculateType(calculateType);
//        orderBean.setGoodsCount(goodsCount);
//        return orderBean;
//    }

    /**
     * 保存经纬度
     *
     * @param context
     * @param gps_x   经度
     * @param gps_y   纬度
     */
    public static void saveLocation(Context context, String gps_x, String gps_y) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(
                "paigeLocation", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("gps_x", gps_x);
        editor.putString("gps_y", gps_y);
        editor.commit();
    }

    /**
     * 保存经纬度(计算距离)
     *
     * @param context
     * @param gps_x   经度
     * @param gps_y   纬度
     */
    public static void saveLocationS(Context context, String gps_x, String gps_y) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(
                "paigeLocationS", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("gps_x", gps_x);
        editor.putString("gps_y", gps_y);
        editor.commit();
    }

    /**
     * 保存经纬度(计算距离)
     *
     * @param context
     * @param gps_x   经度
     * @param gps_y   纬度
     */
    public static void saveLocationR(Context context, String gps_x, String gps_y) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(
                "paigeLocationR", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("gps_x", gps_x);
        editor.putString("gps_y", gps_y);
        editor.commit();
    }

    /**
     * 获取经纬度
     *
     * @param context
     * @return
     */
    public static LocationBean
    getLocation(Context context) {
        LocationBean locationBean = new LocationBean();
        SharedPreferences sharedPreferences = context.getSharedPreferences(
                "paigeLocation", Context.MODE_PRIVATE);
        String gps_x = sharedPreferences.getString("gps_x", "");
        String gps_y = sharedPreferences.getString("gps_y", "");
        locationBean.setGps_x(gps_x);
        locationBean.setGps_y(gps_y);
        return locationBean;
    }

    /**
     * 获取经纬度(计算距离)
     *
     * @param context
     * @return
     */
    public static LocationBean getLocationS(Context context) {
        LocationBean locationBean = new LocationBean();
        SharedPreferences sharedPreferences = context.getSharedPreferences(
                "paigeLocationS", Context.MODE_PRIVATE);
        String gps_x = sharedPreferences.getString("gps_x", "");
        String gps_y = sharedPreferences.getString("gps_y", "");
        locationBean.setGps_x(gps_x);
        locationBean.setGps_y(gps_y);
        return locationBean;
    }

    /**
     * 获取经纬度(计算距离)
     *
     * @param context
     * @return
     */
    public static LocationBean getLocationR(Context context) {
        LocationBean locationBean = new LocationBean();
        SharedPreferences sharedPreferences = context.getSharedPreferences(
                "paigeLocationR", Context.MODE_PRIVATE);
        String gps_x = sharedPreferences.getString("gps_x", "");
        String gps_y = sharedPreferences.getString("gps_y", "");
        locationBean.setGps_x(gps_x);
        locationBean.setGps_y(gps_y);
        return locationBean;
    }

    /**
     * 保存用户的姓名
     *
     * @param context
     * @param name
     */
    public static void saveMyInfo(Context context, String name, String jsonArea, String payPasswordStauts, String bankStauts) {
        SharedPreferences sharedPreferences = context.getSharedPreferences(
                "paigeName", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString("name", name);
        editor.putString("jsonArea", jsonArea);
        editor.putString("payPasswordStauts", payPasswordStauts);
        editor.putString("bankStauts", bankStauts);
        editor.commit();
    }

    /**
     * 获取姓名
     *
     * @param context
     * @return
     */
    public static MyInfoBean getMyInfo(Context context) {
        MyInfoBean myInfoBean = new MyInfoBean();
        SharedPreferences sharedPreferences = context.getSharedPreferences("paigeName", Context.MODE_PRIVATE);
        String name = sharedPreferences.getString("name", "");
        String jsonArea = sharedPreferences.getString("jsonArea", "");
        String payPasswordStauts = sharedPreferences.getString("payPasswordStauts", "");
        String bankStauts = sharedPreferences.getString("bankStauts", "");
        myInfoBean.setName(name);
        myInfoBean.setJsonInfolist(jsonArea);
        myInfoBean.setPayPasswordStauts(payPasswordStauts);
        myInfoBean.setBankStauts(bankStauts);
        return myInfoBean;
    }

    /**
     * 保存显示交换任务对话框状态
     *
     * @param context
     * @param isHide
     */
    public static void saveShowChangeTaskTipsDialogStatus(Context context, boolean isHide) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("showChangeTaskTipsDialogStatus", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean("isHide", isHide);
        editor.apply();
    }

    /**
     * 获取显示交换任务对话框状态
     *
     * @param context
     */
    public static boolean getShowChangeTaskTipsDialogStatus(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("showChangeTaskTipsDialogStatus", Context.MODE_PRIVATE);
        boolean isHide = sharedPreferences.getBoolean("isHide", true);
        return isHide;
    }
}